layui.config({
    base : "/dhjdglxt/modules/util/"//自定义加载的模块
}).use(['form','layer','jquery','layedit','laydate','laypage','table','commUtil','element','treetable'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;
    var table = layui.table;
    var commUtil = layui.commUtil;
    var element = layui.element;
    var treetable = layui.treetable;//很重要
    laydate.render({
	    elem: '#s_ghGxdate',
	    trigger: 'click',
	    type:'year'
	});
    laydate.render({
	    elem: '#s_proctionDate',
	    trigger: 'click',
	    type:'date'
	});
    //监听工具条
    table.on('tool(modelInfo)', function(obj){
        var data = obj.data;
        if(obj.event === 'delete'){
            onDelete(data.recId);
        }else if(obj.event === 'edit'){
            onEdit(data.recId,data);
        }else if(obj.event === 'view'){
            onView(data.recId,data);
        }else if(obj.event === 'bg'){
        	bg(data.recId);
        }else if(obj.event === 'viewProcess'){
        	viewProcess(data.flowInsId);
        }else if(obj.event === 'openDb'){
        	openDb(data.recId);
        }if(obj.event === 'uphold'){
        	uphold(data.recId,data);
        } 
    });
    
    table.on('sort(modelInfo)',function(obj){
    	
    	var s_airModel = $('#s_airModel').val();
    	var s_sign = $('#s_sign').val();
    	var s_ccxlh = $('#s_ccxlh').val();
    	var s_airZt = $('#s_airZt').val();
    	var s_nature = $('#s_nature').val();
    	var s_haveName = $('#s_haveName').val();
    	var s_dtNo = $('#s_dtNo').val();
    	var s_maxZl = $('#s_maxZl').val();
    	var s_proctionDate = $('#s_proctionDate').val();
    	
        //执行重载
        table.reload('modelInfo', {
        	initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
            	s_field: obj.field, //排序字段   在接口作为参数字段  field order
                s_order: obj.type, //排序方式   在接口作为参数字段  field order
            	s_airModel: s_airModel,
            	s_sign: s_sign,
            	s_ccxlh: s_ccxlh,
            	s_airZt: s_airZt,
            	s_nature: s_nature,
            	s_haveName: s_haveName,
            	s_dtNo: s_dtNo,
            	s_proctionDate: s_proctionDate,
            	s_maxZl:s_maxZl
            }
        });
    });
    
    //导入
    layui.use(['upload'],function(){
        var upload = layui.upload;

        upload.render({
            elem : '#onImportGcwt',
            method: 'post',
            url : basePath+'/service/dbRecord/uploadSftjb',
            accept : 'file',
            exts: 'xls|xlsx',
            done : function(res) {
                layer.msg("导入成功",{icon:0});
                onQuery();
            }
        });


    });



    $(".onQuery").click(function(){
        onQuery();
    })

    $(".onAdd").click(function(){
    	onAdd();
    })
    
    /*
    **新增
    */
    function onAdd(){
        var index = layui.layer.open({
            title : "编辑",
            type : 2,
            skin:'layui-layer-molv',
            area:['100%','100%'],
            offset: 't',
            content : basePath + '/service/airplanebaseinfo/airplanebaseinfo/'+0+"/edit",
            success : function(layero, index){
                setTimeout(function(){
                    layer.style(index, {
                        top: 0,
                        height: window.innerHeight
                    });
                },100);
            }
        });
        ////layui.layer.full(index);
    }
    
    //查询
    function onQuery(){
    	var s_recordTitle = $('#s_recordTitle').val();
    	
        //执行重载
        table.reload('modelInfo', {
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                recordTitle: s_recordTitle
            }
        });
    }
    function openDb(flowRecId){
    	$("#transContents").val("");
    	  var index = layui.layer.open({
              title : "编辑",
              type : 2,
              skin:'layui-layer-molv',
              area:['100%','100%'],
              offset: 't',
              content : basePath + '/service/airplanebaseinfo/airplanebaseinfo/'+flowRecId+"/openDb",
              success : function(layero, index){
                  setTimeout(function(){
                      layer.style(index, {
                          top: 0,
                          height: window.innerHeight
                      });
                  },100);
              }
          });
          //layui.layer.full(index);
    }
    
  //删除
    function onDelete(recId){
        layer.confirm('您确定要删除吗？',{icon:3, title:'提示信息'}, function(index){
            $.ajax({
                type: "DELETE",
                url: basePath + '/service/dbRecord/' + recId,
                async: false,
                dataType: "json",
                success: function (data) {
                    layer.msg("操作成功！",{icon:1});
                    onQuery();
                }
            });
        });
    }
  //发布
    function fb(recId){
        layer.confirm('发布将无法修改，您确定要发布吗？',{icon:3, title:'提示信息'}, function(index){
            $.ajax({
                type: "GET",
                url: basePath + '/service/jdghgl/jdghgl/fb/' + recId,
                async: false,
                dataType: "json",
                success: function (data) {
                    layer.msg("操作成功！",{icon:1});
                    onQuery();
                }
            });
        });
    }
    //编辑
    function onEdit(recId,data){
            var index = layui.layer.open({
                title : "编辑",
                type : 2,
                skin:'layui-layer-molv',
                area:['100%','100%'],
                offset: 't',
                content : basePath + '/service/dbRecord/'+recId+"/edit",
                success : function(layero, index){
                    setTimeout(function(){
                        layer.style(index, {
                            top: 0,
                            height: window.innerHeight
                        });
                    },100);
                }
            });
            //layui.layer.full(index);
    }
    //维护
    function uphold(recId,data){
            var index = layui.layer.open({
                title : "编辑",
                type : 2,
                skin:'layui-layer-molv',
                area:['100%','100%'],
                offset: 't',
                content : basePath + '/service/airplanebaseinfo/airplanebaseinfo/'+recId+"/uphold",
                success : function(layero, index){
                    setTimeout(function(){
                        layer.style(index, {
                            top: 0,
                            height: window.innerHeight
                        });
                    },100);
                }
            });
            //layui.layer.full(index);
    }
    
    //变更
    function bg(recId,data){
            var index = layui.layer.open({
                title : "变更",
                type : 2,
                skin:'layui-layer-molv',
                area:['100%','100%'],
                offset: 't',
                content : basePath + '/service/airplanebaseinfo/airplanebaseinfo/'+recId+"/bg",
                success : function(layero, index){
                    setTimeout(function(){
                        layer.style(index, {
                            top: 0,
                            height: window.innerHeight
                        });
                    },100);
                }
            });
            //layui.layer.full(index);
    }
    //查看流程图
    function viewProcess(flowInstId) {
        $(window).one("resize", function () {
			openDiv("950px","600px","/apprFlow/page/workflow/flowView.html?flowInstId="+flowInstId+"&contentPath=/apprFlow/","查看流程图")
        }).resize();
    }
    //查看
    function onView(recId,data){
            var index = layui.layer.open({
                title : "查看",
                type : 2,
                skin:'layui-layer-molv',
                area:['100%','100%'],
                offset: 't',
                content : basePath + '/service/dbRecord/'+recId+"/gcwt",
                success : function(layero, index){
                    setTimeout(function(){
                        layer.style(index, {
                            top: 0,
                            height: window.innerHeight
                        });
                    },100);
                }
            });
            //layui.layer.full(index);
    }
})
function HTMLDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
} 
